import 'package:flutter/foundation.dart';
import 'package:networking/src/http_code/nw_http_code.dart';

class NWError implements Exception {
  final NWErrorCode code; // 一般是业务的代码
  final HttpCode? httpCode; // http代码
  final String msg; // 错误信息
  final dynamic error; // 如果http code != 200， 此处将有值

  NWError(this.code, this.httpCode, this.msg, {this.error});
}

@immutable
class NWErrorCode {
  final int rawValue;
  final String describe;
  const NWErrorCode(this.rawValue, this.describe);

  @override
  bool operator ==(Object other) => (other is NWErrorCode) && (other.rawValue == rawValue);

  @override
  int get hashCode => rawValue;

  static const unknown = NWErrorCode(-1, "未知错误");
  static const network = NWErrorCode(0, "连接远端服务器失败");
  static const oauth = NWErrorCode(1, "当前登录已过期");
  static const analysis = NWErrorCode(2, "数据解析失败");
  static const serverCode = NWErrorCode(3, "请求成功，但是业务代码非0");
  static const etag = NWErrorCode(4, "请求成功，但是Etag错误");
  static const refreshingToken = NWErrorCode(5, "正在更新token");
  static const imageCaptcha = NWErrorCode(302, "请输入图形验证码");
}

// class OtherErrorCode extends NWErrorCode {
//   const OtherErrorCode(super.rawValue);

//   static const oauth = NWErrorCode(1);
// }
